/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.qframe.quickc;

import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.code.Type;
import javax.lang.model.element.TypeElement;

/**
 *
 * @author gprasad
 */
public class Util {

    public static boolean doesTypeInheritInterface(TypeElement typeElement, String interfaceQuilifiedName) {
        if(typeElement == null){
            return false;
        }
        List<Type> interfaces = (List<Type>) typeElement.getInterfaces();
        for (Type type : interfaces) {
            boolean gotit = type.asElement().getQualifiedName().toString().equals(interfaceQuilifiedName);
            if (gotit) {
                return true;
            } else {
                TypeElement innerTypeElement = (TypeElement) type.asElement();
                gotit = doesTypeInheritInterface(innerTypeElement, interfaceQuilifiedName);
                if (gotit) {
                    return true;
                }
            }

        }
        Type superType = (Type) typeElement.getSuperclass();
        if (superType == null) {
            return false;
        }
        ClassSymbol superClazz = (ClassSymbol) superType.asElement();
        return doesTypeInheritInterface(superClazz, interfaceQuilifiedName);
    }
}
